import { updateStatusApi } from 'api/operation/banner';
import { message } from 'tdesign-react';
export const type_MAP = {
  15: '原生',
  9999: '非原生',
};

export const PARRENT_TYPE_OPTIONS = {
  8: 'IPFly',
  11: 'Spark',
};


export function getBLOG_CATEGORY_MAP(lang: 'zh' | 'en'){
  return BLOG_CATEGORY_MAP.map(item => ({
    label: item.label[lang],
    value: item.value,
  }));
}

export const BLOG_CATEGORY_MAP = [
  {
    label:{
      zh: '最新',
      en: 'News',
    },
    value: 74,
  },
  {
    label:{
      zh: '住宅代理',
      en: 'Residential Proxies',
    },
    value: 75,
  },
  {
    label:{
      zh: '应用场景',
      en: 'Use Cases',
    },
    value: 76,
  },
  {
    label:{
      zh: '代理技巧',
      en: 'Proxy Tips',
    },
    value: 77,
  },
]


export const handleUpdateStatus = async (
  newValue: boolean,
  row: any, 
  setUpdatingRows: React.Dispatch<React.SetStateAction<Set<string | number>>>, 
  setTable: React.Dispatch<React.SetStateAction<any>>
) => {
  try {
    setUpdatingRows((prev: Set<string | number>) => new Set(prev).add(row.id));
    const res = await updateStatusApi(row.id, { ...row, status: newValue });
    setTable((prev: any) => ({
      ...prev,
      list: prev.list.map((item: any) => 
        item.id === row.id 
          ? { ...item, deleted:!newValue }
          : item
      )
    }));
    message.success('操作成功');
  } catch (err) {
    console.log(err);
    message.error('操作失败');
  } finally {
    setUpdatingRows((prev: Set<string | number>) => {
      const newSet = new Set(prev);
      newSet.delete(row.id);
      return newSet;
    });
  }
};